#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>

int main(){
    // Open Camera
    cv::VideoCapture input_stream(0);
        // check
    if(! input_stream.isOpened()){
        std::cerr<<"Could not open camera\n";
        return EXIT_FAILURE;
    }
    
    // Create Display Window
    const std::string window_tile = "Grayscale Video";
    cv::namedWindow(window_tile,cv::WINDOW_NORMAL);

    cv::Mat frame,gray_frame;
    while (true){
        // Capture a frame
        input_stream >> frame;
        if(frame.empty()){
            break;
        }
        // Convert color to gray
        cv::cvtColor(frame, gray_frame, cv::COLOR_BGR2GRAY);
        // display gray frames
        cv::imshow(window_tile, gray_frame);

        // Press the Esc key to Exit
        if(cv::waitKey(15) == 27){
            break;
        }
    }
    // Release resource
    input_stream.release();
    cv::destroyAllWindows();

    return 0;
}